/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.jgls.bi.dataprocess;

import java.util.ArrayList;
import java.util.Iterator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.sql.DataSource;

/**
 *
 * @author zz
 */
public class ThreadWorker extends Thread {

    DataProcessJdbcDao tsDao = new DataProcessJdbcDao();
    java.sql.Date ldDate;
    int iShopId, iDateNo, iYybh, iManId, iBj;
    String sShopBm, sYear, sTab;
    DataSource ds;
    ArrayList<String> fctName = new ArrayList<String>();
    int i;
    String ls_fname;
    Iterator ShopIter1;
    ArrayList<ArchiDept> lad = new ArrayList<ArchiDept>();

    ThreadWorker(ArrayList<ArchiDept> lArchiD) {
        lad = lArchiD;
    }

    public void setParam(java.sql.Date adTsnDate, int aiShopId, String asShopBm,
            int aiDateNo, String asYear, int aiYybh, int aiMan_id, String asTname) {
        this.ldDate = adTsnDate;
        this.iShopId = aiShopId;
        this.sShopBm = asShopBm;
        this.iDateNo = aiDateNo;
        this.sYear = asYear;
        this.iYybh = aiYybh;
        this.iManId = aiMan_id;
        this.sTab = asTname;
    }

    public void setParm(java.sql.Date adTsnDate, int aiDateNo, String asYear, String asTname, String asFname) {
        this.ldDate = adTsnDate;
        this.iDateNo = aiDateNo;
        this.sYear = asYear;
        this.sTab = asTname;
        this.ls_fname = asFname;
    }

    @Override
    public void run() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringConfig_Jdbc.xml");
        ds = (DataSource) ctx.getBean("dataSourceDBDirect");
        ArchiDept ad = new ArchiDept();
        //取总部
        sShopBm="all";
        if (ls_fname.equalsIgnoreCase("batchupdate")) {
            tsDao.setDataSource(ds);
            tsDao.TsnAmt(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
        }
        //取1部
        sShopBm="yyb1";
        if (ls_fname.equalsIgnoreCase("batchupdate")) {
            tsDao.setDataSource(ds);
            tsDao.TsnAmt(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
        }
        //取2部
        sShopBm="yyb2";
        if (ls_fname.equalsIgnoreCase("batchupdate")) {
            tsDao.setDataSource(ds);
            tsDao.TsnAmt(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
        }
        //取3部
        sShopBm="yyb3";
        if (ls_fname.equalsIgnoreCase("batchupdate")) {
            tsDao.setDataSource(ds);
            tsDao.TsnAmt(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
        }

        //按门店取值
        for (i = 0; i < lad.size(); i++) {
            //while (ShopIter1.hasNext()) {
            ad = lad.get(i);
            iShopId = ad.getId();
            sShopBm = ad.getBm();
            iYybh = ad.getYybh();
            iManId = ad.getMan_id();
            //判断要调用哪个方法
            //1、A报表-交易笔数 tsnamt
            if (ls_fname.equalsIgnoreCase("batchupdate")) {
                tsDao.setDataSource(ds);
                tsDao.TsnAmt(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
         }
    }
}
